package com.fenxiangle.yueding.feature.focus.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fenxiangle.yueding.R;
import com.fenxiangle.yueding.entity.bo.AliPayBo;
import com.fenxiangle.yueding.entity.bo.MyAccountBo;
import com.fenxiangle.yueding.feature.mine.view.MyCreditActivity;
import com.fenxiangle.yueding.feature.mine.view.MyServiceActivity;
import com.fenxiangle.yueding.feature.publish.contract.PayContract;
import com.fenxiangle.yueding.feature.publish.dependencies.pay.DaggerPayComponent;
import com.fenxiangle.yueding.feature.publish.dependencies.pay.PayPresenterModule;
import com.fenxiangle.yueding.framework.DataServer;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Home on 2018/9/1.
 */

public class MeAccountActivity extends BaseActivity implements Toolbar.OnMenuItemClickListener, PayContract.View {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.btn_show_money)
    TextView mBtnShowMoney;
    @BindView(R.id.btn_my_cerdit)
    RelativeLayout mBtnMyCerdit;
    @BindView(R.id.btn_my_service_fee)
    RelativeLayout mBtnMyServiceFee;

    private MyAccountBo mAccountBo;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_me_account;
    }

    @Inject
    PayContract.Presenter mPresenter;

    @Override
    protected void initInjector() {
        DaggerPayComponent.builder().payPresenterModule(new PayPresenterModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        initToolBar(toolbar, "我的账户", true, true);

        toolbar.inflateMenu(R.menu.menu_next);
        toolbar.setOnMenuItemClickListener(this);

        if (AM.user().isLogin()){
            if (AM.user().getLoginResultCache().getUserPhone().equals(DataServer.LOCAL_USER)){
                mBtnMyCerdit.setVisibility(View.GONE);
                mBtnMyServiceFee.setVisibility(View.GONE);
                mBtnMyCerdit.setVisibility(View.GONE);
                mBtnMyServiceFee.setVisibility(View.GONE);
            }else {
                mBtnMyCerdit.setVisibility(View.VISIBLE);
                mBtnMyServiceFee.setVisibility(View.VISIBLE);
                mBtnMyCerdit.setVisibility(View.VISIBLE);
                mBtnMyServiceFee.setVisibility(View.VISIBLE);
            }
        }
    }

    @Override
    protected void initData() {
        mPresenter.getMyAccount();
    }

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        int menuItemId = item.getItemId();
        if (menuItemId == R.id.action_wallet_detail) {
            Intent intent = new Intent(MeAccountActivity.this, WalletDetailActivity.class);
            startActivity(intent);
        }
        return false;
    }


    @OnClick({R.id.btn_my_cerdit, R.id.btn_my_service_fee})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_my_cerdit:
                startActivity(new Intent(this, MyCreditActivity.class));
                break;
            case R.id.btn_my_service_fee:
                startActivity(new Intent(this, MyServiceActivity.class));
                break;
        }
    }

    @Override
    public void showAliPayData(String aliPayData) {

    }

    @Override
    public void showWxPayData(AliPayBo.WechatBo wechatBo) {

    }

    @Override
    public void showError(String error) {
        showMsg(error);
    }

    @Override
    public void showAccountSuccess(MyAccountBo aliPayData) {
        mBtnShowMoney.setText(aliPayData.getTotal() + "元");
    }
}
